﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using LabMS.BLL;
using LabMS.Model;

namespace LabMS.Web.LabPersonnel
{
    public partial class ChooseCourseList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGridViewList("");
            }
        }

        protected void BindGridViewList(string strWhere)
        {
            LabMS.BLL.Course course = new LabMS.BLL.Course();
            List<LabMS.Model.Course> courselist = new List<LabMS.Model.Course>();

            courselist = course.GetModelList(strWhere);
            gvCourseList.DataSource = courselist;
            gvCourseList.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strWhere = " like ";
            string strcondition = ddlSType.SelectedValue;
            if (strcondition == "0")
            {
                strWhere = " Course_Code " + strWhere;
            }
            else
            {
                strWhere = " Course_Name " + strWhere;
            }
            strWhere = strWhere + " '%" + tbKeyWord.Text.Trim() + "%' ";

            BindGridViewList(strWhere);
        }

        protected void GridViewCourse_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvCourseList.PageIndex = e.NewPageIndex;
            string strWhere = " like ";
            string strcondition = ddlSType.SelectedValue;
            if (strcondition == "0")
            {
                strWhere = " Course_Code " + strWhere;
            }
            else
            {
                strWhere = " Course_Name " + strWhere;
            }
            strWhere = strWhere + " '%" + tbKeyWord.Text.Trim() + "%' ";

            BindGridViewList(strWhere);
        }

        protected void GridViewCourse_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor='White';this.style.color='#003399'");
                //e.Row.Attributes.Add("OnMouseOver", "this.style.backgroundColor='#6699FF';this.style.color='#8C4510'");
                e.Row.Attributes["style"] = "Cursor:pointer";
            }

        }
        //protected void btSubmit_Click(object sender, EventArgs e)
        //{
        //    CheckBox cb;
        //    LabMS.BLL.Course courses = new LabMS.BLL.Course();
        //    string courseCode = "";
        //    string courseName = "";
        //    int checkboxChecked = 0;
        //    for (int i = 0; i < gvCourseList.Rows.Count; i++)
        //    {
        //        cb = (CheckBox)gvCourseList.Rows[i].FindControl("CourseCB");
        //        if (cb.Checked)
        //        {
        //            checkboxChecked += 1;
        //            courseCode += gvCourseList.Rows[i].Cells[0].Text.Trim() + ";";
        //            courseName += gvCourseList.Rows[i].Cells[1].Text.Trim() + ";";
        //        }
        //    }
        //    if(checkboxChecked != 0)
        //    {
        //        IDHF1.Value = courseCode.Substring(0, courseCode.Length - 1);
        //        IDHF2.Value = courseName.Substring(0, courseName.Length - 1);
        //    }
        //    else
        //    {
        //        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>window.close()</script>");
        //    }
        //}
    }
}
